import React from 'react';
import {
  View,
  WebView,
  ScrollView,
  Text,
  TouchableOpacity,
  Platform,
  Image
} from 'react-native';

import {DateUtils, HtmlUtils} from '../../utils/Utils';
import NewsConstants from '../../common/NewsConstants';
import SizeUtils from '../../common/SizeUtils';
import Constants from '../../common/Constants';
import TImage from '../../components/TImage';
import PostContentPage from '../post/PostContentPage';
import NewsRequestContentAction from '../../actions/news/NewsRequestContentAction';
import NewsRequestCommonListAction from '../../actions/news/NewsRequestCommonListAction';
import NewsRequestLikeAction from '../../actions/news/NewsRequestLikeAction';
import NewsRequestNewsByTopicsAction from '../../actions/news/NewsRequestNewsByTopicsAction';
import NewsListItemView from './NewsListItemView';

export default class NewsContentPage extends PostContentPage {
  constructor(props) {
    super(props);

    this._showShoucang = false;
    this._showZan = true;
    this._showCommentAfterContent = true;
    this._canVideoFullScreen = true;
    this._showRecommend = true;
    this._showShoucang=true;
    this._showZan=true;

    this._postDataKeyName = "news_id";
  }
 _initShowTag() {
    super._initShowTag();
    if (this.props.pageData.routeData.isGongGao) {
      this._showFooterBar = false;
      this._showShoucang=false;
      this._showCommentAfterContent = false;
    }
  }
  _getShareData() {
    return {type:Constants.MODULE_TYPE.NEWS, news_id:this.state.postData.news_id, title:this.state.postData.title}
  }

  _sendRequestDataAction() {
    new NewsRequestContentAction().call(this, {news_id:this.props.pageData.routeData.news_id});
  }

  _sendRequestRecommentListAction(sendData) {
    sendData.topics = this.state.postData.topics;
    new NewsRequestNewsByTopicsAction().call(this, sendData)
  }
  _getShoucangImageSource() {
    if(this.state.postData.is_favorited == 1) {
      return require("../../../resource/images/common/shoucangy.png");
    }
    else {
      return require("../../../resource/images/common/shoucang.png");
    }
  }
  _getZanImageSource() {
    if(this.state.postData.is_liked == 1) {
      return require("../../../resource/images/common/dianzan.png");
    }
    else {
      return require("../../../resource/images/common/dianzanr.png");
    }
  }
  _renderZanView(){
    if(this._showZan === false) {
      return;
    }
    return(
      <View style={{
        height:SizeUtils.translateDesignHeightToCode(100),
        alignItems: 'center',justifyContent: 'center',
      }}>
        <TouchableOpacity onPress={this._onPressLikeBtn.bind(this)} style={{
          width:SizeUtils.translateDesignWidthToCode(200),
          height:SizeUtils.translateDesignHeightToCode(60),
          borderRadius:SizeUtils.translateDesignHeightToCode(60),
          borderWidth:0.5,
          borderColor:this.state.postData.is_liked == 1?'#ee3535':'#e3e3e3',
          justifyContent: 'center',alignItems: 'center',
          flexDirection:'row',
        }}>
          <TImage source={this._getZanImageSource()}
              style={{width:34, height:34}}/>
            {/**<Text style={{marginLeft:5,color:this.state.postData.is_liked == 1?'#ee3535':'#e3e3e3',fontSize:SizeUtils.translateFontSizeToCode(22)}}>{this._getLinkNum()}
            </Text>**/}
        </TouchableOpacity>
      </View>
    );
  }
  _getSource() {
    let name = ""
    if(this.state.postData.source != undefined) {
      name = this.state.postData.source;
    }
    else if (this.state.postData.by_name != undefined) {
      name = this.state.postData.by_name;
    }

    let readersNum = "";
    if(this.state.postData != null && this.state.postData.readers_num != undefined)
    {
      readersNum = "浏览：" + this.state.postData.readers_num;
    }

    source = name + "  " + DateUtils.formatDate2(this.state.postData.posted_at) + "  " + readersNum;
    return source;
  }

  // 推荐阅读
  _renderRecommendItem(data, index) {
    return (
      <View key={index} >
        <NewsListItemView data={data} style={{paddingLeft:0, paddingRight:0,
          width:SizeUtils.getWindowSize().width -  SizeUtils.translateDesignWidthToCode(80)}}/>
      </View>
    )
  }

  _getModuleType() {
    return Constants.MODULE_TYPE.NEWS;
  }

  _sendRequestCommentListAction(page = 1) {
    let data = {page:page, page_size:10, news_id:this.props.pageData.routeData.news_id};
    new NewsRequestCommonListAction().call(this, data);
  }

  _sendLikeAction() {
    if(this.state.isUpdateSomething){
      return;
    }
    new NewsRequestLikeAction().call(this, this.state.postData);
  }
}
